package com.kingre.et.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.kingre.et.dao.IDimensioScoreDAO;
import com.kingre.et.dao.IRawdataDAO;
import com.kingre.et.dao.IUserDAO;
import com.kingre.et.model.DimensioScore;
import com.kingre.et.model.Rawdata;
import com.kingre.et.model.User;
import com.kingre.et.service.IDisReportService;
import com.kingre.et.util.FormulaUtils;

@Transactional
public class DisReportServiceImpl implements IDisReportService {
    @Autowired
    private IUserDAO userDAO;
    @Autowired
    private IDimensioScoreDAO imensioScoreDAO;
    @Autowired
    private IRawdataDAO rawdataDAO;

    @Override
    public List<Rawdata> getRawdata(Integer userId) {
        User user = userDAO.get(userId);
        List<Rawdata> list = rawdataDAO.findByUser(user);
        for (Rawdata r : list) {
            r.getQuestion().getName();
        }
        return list;
    }

    @Override
    public List<DimensioScore> getDimensioScore(Integer userId) {
        User user = userDAO.get(userId);
        List<DimensioScore> list = imensioScoreDAO.findByUser(user);
        for (DimensioScore ds : list) {
            ds.getDimensionality().getName();
        }
        return list;
    }

    @Override
    public User getUser(Integer userId) {
        return userDAO.get(userId);
    }

    @Override
    public Integer getFlamScore(Integer userId) {
        User user = userDAO.get(userId);
        return 10 - FormulaUtils.getAVGToInt(rawdataDAO.getStandardScore(user, 82),
                rawdataDAO.getStandardScore(user, 83), rawdataDAO.getStandardScore(user, 84));
    }

}
